$('.js-tilt').tilt({
    scale: 1.1
});

function upload() {
    $('#upload').ajaxSubmit(function (message) {
            var message1 = $.parseJSON(message);
            if (message1.code == 0) {
                $('#textUpload').val(message1.message);
                $('.file-msg').text("上传成功");
                $('.file-msg').css("color", "#66CD00");
            } else {
                $('.file-msg').text("上传失败");
                $('.file-msg').css("color", "#FF0000");
            }
        }
    )
}



function formatJson(json){
    var newJson = "";
    var spaceLength = 0;
    while (true){
        var comma = json.indexOf(",");
        var formerBracket = json.indexOf("[");
        var latterBracket = json.indexOf("]");
        var former = json.indexOf("{");
        var latter = json.indexOf("}");
        if (latter<0)
            break;

        var min = findMin(comma, formerBracket, latterBracket, former, latter, json.length);
        if (min===former || min===formerBracket) {
            newJson += createSpace(spaceLength++)+json.slice(0,min+1);
        } else if (min===latter||min===latterBracket) {
            if (min===0) {
                newJson += createSpace(--spaceLength)+json.slice(0,min+1);
            } else {
                newJson += createSpace(spaceLength--)+json.slice(0,min)+createSpace(spaceLength)+json.slice(min,min+1);
            }
        } else {
            if (min===0) {
                newJson += json.slice(0,min+1);
            } else {
                newJson += createSpace(spaceLength)+json.slice(0,min+1);
            }
        }

        if (spaceLength<=0)
            break;

        json=json.slice(min+1);
    }

    if (newJson.length===0)
        return json;

    return newJson;
}

function findMin(a, b, c, d, e, max){
    if (a<0) a=max;
    if (b<0) b=max;
    if (c<0) c=max;
    if (d<0) d=max;
    if (e<0) e=max;
    return Math.min(a, b, c, d, e);
}

function createSpace(length){
    var space="\n";
    for(var i=0;i<length;i++){
        space+="  ";
    }
    return space;
}

// control auto-expand of textarea
window.onload=function(){
var area = $('#jpath')[0];
var span = $('#textAreaSpan')[0];
if (area.addEventListener) {
    area.addEventListener('input', function() {
        span.textContent = area.value;
    }, false);
    span.textContent = area.value;
} else if (area.attachEvent) {
    area.attachEvent('onpropertychange', function() {
        var html = area.value.replace(/\n/g,'<br/>');
        span.innerText = html;
    });
    var html = area.value.replace(/\n/g,'<br/>');
    span.innerText = html;
}
if(window.VBArray && window.addEventListener) { //IE9
    area.attachEvent("onkeydown", function() {
        var key = window.event.keyCode;
        if(key == 8 || key == 46) span.textContent = area.value;

    });
    area.attachEvent("oncut", function(){
        span.textContent = area.value;
    });//handle of copy
}
area.className += "active";}